<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        var arr =[3,7,1,8,4,5,9,2]
        for(var i in arr){
            for (var j in arr){
                if(arr[i]<arr[j]){
                    var x =arr[i]
                    arr[i]=arr[j]
                    arr[j]=x
                }
            }
        } 
        console.log(arr)
    </script>
</body>
</html>